//	 Copyright 2011 Elian ORIOU
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.

package org.eo.geomapper.objects;

/**
 * Defines a Geographical Point object
 * 
 * @author Elian ORIOU
 * 
 */

public class GeoPoint implements IObject {

	private String name;
	private int x;
	private int y;

	public GeoPoint(int x, int y) {
		this(null, x, y);
	}

	public GeoPoint(String name, int x, int y) {
		this.name = name;
		this.x = x;
		this.y = y;
	}

	/**
	 * Returns the X coordinate
	 * 
	 * @return the X coordinate
	 */

	public int getCoordX() {
		return this.x;
	}

	/**
	 * Returns the Y coordinate
	 * 
	 * @return the Y coordinate
	 */

	public int getCoordY() {
		return this.y;
	}

	/**
	 * Returns the name of the point
	 * 
	 * @return the name of the point
	 */

	@Override
	public String getName() {
		return this.name;
	}

	/**
	 * Sets the point name
	 * 
	 * @param name
	 *            the new point name
	 */

	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		if (name == null) {
			return "Point [x=" + x + ", y=" + y + "]";
		}
		return "Point [name=" + name + ", x=" + x + ", y=" + y + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GeoPoint other = (GeoPoint) obj;
		if (x != other.x)
			return false;
		if (y != other.y)
			return false;
		return true;
	}

}